import { AppDispatch } from '..'
import http from '../../utils/request'

// 获取频道列表
export const getNewsList = (channel_id: number) => {
  return async (dispatch: AppDispatch) => {
    // 发送请求获取数据
    const res = await http.get('/v1_0/articles', {
      params: {
        channel_id: channel_id,
        timestamp: Date.now(),
      },
    })
    console.log(res)
    // 调用 dispatch 存到仓库中
    dispatch({ type: 'news/saveList', payload: res.data.results })
  }
}
